package com.njupt.service;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.transform.ResultTransformer;

import com.njupt.dao.PaginationSupport;


public interface GenericPaginationManager<T, PK extends Serializable> {

	public abstract T save(T entity);
	public void delete(T entity);
	void remove(PK id);
	List findByHql(String hql, Object... params);
	List find(String hql, Object... params);
	List find(String hql);
	
	List findByCriteria(DetachedCriteria dc);
	T get(PK id);
	T findUniqueBy(String propertyName, Object value);
	int executeUpdate(String hql, Object...params);
	/**
	 * 针对返回一条数据的情况。
	 * 
	 * @param hql
	 * @param params
	 * @return
	 */
	T queryUniqueResult(String hql, Object... params);
	/**
	 * 执行一个DetachedCriteria，获取单条数据。
	 * @param detachedCriteria
	 * @return
	 */
	T queryUniqueResult(final DetachedCriteria detachedCriteria);
	/**
	 * 执行修改数据的sql。
	 * @param nativeSql
	 * @param params
	 * @return
	 */
	int executeUpdateByNativeSql(String nativeSql, Object[] params);
	
	//----------------------by criteria---------------------
	PaginationSupport findPageByCriteria(
			 DetachedCriteria detachedCriteria,
			 int startIndex, int pageSize);
	PaginationSupport findPageByCriteria(DetachedCriteria detachedCriteria,
			int startIndex, int pageSize, ResultTransformer resultTransformer);
	
	PaginationSupport paginateByCriteria(DetachedCriteria detachedCriteria,
			int pageNo,
			int pageSize, ResultTransformer resultTransformer);
	PaginationSupport paginateByCriteria(
			 DetachedCriteria detachedCriteria,
			 int pageNo, int pageSize);
	
	


	//-------------------by example----------------------
	PaginationSupport findByExample(Object example, int startIndex, int pageSize);
	PaginationSupport paginationByExample(Object object, int pageNo, int pageSize);

	
	//----------------------by hql----------------------
	PaginationSupport findPageByHql(String hql, int startIndex, int pageSize);

	PaginationSupport findPageByHql(String hql, int startIndex, int pageSize, Object... params);

	PaginationSupport findPageByHql(String hql, String vCountHql, int startIndex, Object... params);

	PaginationSupport findPageByHql(String hql, String vCountHql, int startIndex, int pageSize, Object... params);
	
	PaginationSupport paginateByHql(
			 String hql,
			 int pageNo, int pageSize,Object ... params);
}

